import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class P1083 {
    static int n, m;
    static int[] days;
    static int[] usedNumbers;
    static int[] starts;
    static int[] ends;
    static int output = -1;

    public static boolean ifOK(int x) {
        long[] pre_used = new long[n + 2];
        long[] needs = new long[n + 2];

        for (int i = 1; i <= x; i++) {
            pre_used[starts[i]] += usedNumbers[i];
            pre_used[ends[i] + 1] -= usedNumbers[i];
        }
        for (int i = 1; i <= n; i++) {
            needs[i] = needs[i-1] + pre_used[i];
            if(needs[i] > days[i]) return false;
        }
        return true;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String tmp = br.readLine();
        n = Integer.parseInt(tmp.split(" ")[0]);
        m = Integer.parseInt(tmp.split(" ")[1]);
        days = new int[n + 1];
        tmp = br.readLine();
        String[] tmpStrs = tmp.split(" ");
        for (int i = 1; i <= n; i++) {
            days[i] = Integer.parseInt(tmpStrs[i - 1]);
        }
        usedNumbers = new int[m + 1];
        starts = new int[m + 1];
        ends = new int[m + 1];
        for (int i = 1; i <= m; i++) {
            tmp = br.readLine();
            usedNumbers[i] = Integer.parseInt(tmp.split(" ")[0]);
            starts[i] = Integer.parseInt(tmp.split(" ")[1]);
            ends[i] = Integer.parseInt(tmp.split(" ")[2]);
        }
        int left = 1;
        int right = m;
        while (left <= right) {
            int mid = (left + right) >>> 1;
            if (ifOK(mid)) {
                left = mid + 1;
            } else {
                output = mid;
                right = mid - 1;
            }
        }
        if (output == -1) {
            System.out.println(0);
        } else {
            System.out.println(-1);
            System.out.println(output);
        }
    }
}
